home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5654 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: chaos.kulnet.kuleuven.ac.be!usenet
  2. From: Andreas De Troy <Andreas.DeTroy@ped.kuleuven.ac.be>
  3. Newsgroups: comp.lang.c
  4. Subject: Optimization Q: for( i=0; i<SIZE/2; i++) ??
  5. Date: 20 Feb 1996 09:00:35 GMT
  6. Organization: KUL
  7. Message-ID: <4gc2jj$ojb@chaos.kulnet.kuleuven.ac.be>
  8. NNTP-Posting-Host: pcip194.psy.kuleuven.ac.be
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.2N (Windows; I; 16bit)
  13.  
  14. news:4g1j9n$ooe@news.csus.edu
  15. wleong@sfsu.edu (Jerry Leong) wrote:
  16. >
  17. >If I have the following for loop,
  18. >        for( i=0; i< SIZE/2 ; i++).....
  19. >Will the code execute faster if I precompute SIZE/2 before hand and
  20. >do this
  21. >      k = SIZE/2;
  22. >       for(i=0; i<k ; i++).....
  23. >
  24. >How does this work? I mean, would SIZE/2 get computed everytime during
  25. >the for loop, or it simply caculated once?
  26.  
  27.  
  28. if SIZE is a (pre#defined) constant, it makes no difference.
  29.  
  30. If not, an optimizing compiler should translate both expressions to the 
  31. same code (as long as you do not alter SIZE or k inside the loop of 
  32. course).
  33.  
  34.  
  35.